/*
 * QTextDocumentAdapter.h  0.4.0 / Dec 04, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#ifndef QTEXTDOCUMENTADAPTER_H
#define QTEXTDOCUMENTADAPTER_H

#include "Cute4jSwing.h"

// TextDocumentHighlighter Class. ----------------------------------------------

class QTextDocumentAdapter;

/*!
 * \brief TextDocument Highlighter.
 *
 * \author Slobodan Vrkacevic
 * \version 0.4.0
 */
class CUTE4J_EXPORT TextDocumentHighlighter : public QSyntaxHighlighter
{
  Q_OBJECT
public:
  TextDocumentHighlighter();
public:
  void setDocument(QTextDocumentAdapter *document);
  void setFormat(int start, int length, const QTextCharFormat &format);
protected slots:
  void contentsChangeSlot(int position, int charsRemoved, int charsAdded);
protected:
  virtual void highlightBlock(const QString &text);
private:
  QTextDocumentAdapter *m_document;
  int m_blockPosition;
  bool m_contentsChanged;
};

// QTextDocumentAdapter Class. -------------------------------------------------

class TextDocumentDelegate;

/*!
 * \brief QTextDocument Adapter.
 *
 * \author Slobodan Vrkacevic
 * \version 0.4.0
 */
class QTextDocumentAdapter : public QTextDocument
{
  Q_OBJECT
protected:
  QTextDocumentAdapter(TextDocumentDelegate *delegate);
  virtual ~QTextDocumentAdapter();
public:
  int length();
  void clear();
  void setDestroying();
  void setUseHighlighter(bool useHighlighter);
  void setFormat(int start, int length, const QTextCharFormat &format);
  void highlightBlock(int blockStart, const QString &blockText);
public:
  virtual QString getText() const = 0;
  virtual void setText(const QString &text) = 0;
  virtual void appendText(const QString &text) = 0;
signals:
  void destroying();
  void textCleared();
  void textSet();
  void textAppended();
  void selectAllAvailable(bool available);
protected slots:
  void contentsChangeSlot(int position, int charsRemoved, int charsAdded);
protected:
  int m_length;
  bool m_destroying;
  TextDocumentDelegate *m_delegate;
  TextDocumentHighlighter *m_highlighter;
};

#endif // QTEXTDOCUMENTADAPTER_H
